require 'parseconfig'
require 'socket'
require 'timeout'
require 'mysql'

def insert_sql(port, website, status )
	begin
		#parse values from our .conf
		email_config = ParseConfig.new('login.conf').params
		host = email_config['db_host']
		user = email_config['db_username']
		pass = email_config['db_passwd']
		db_name = email_config['db_name']
	#connect to MySQL
	dbh = Mysql.real_connect(host, user, pass, db_name)
	rescue Mysql::Error => e
	 puts "Error code: #{e.errno}"
	 puts "Error message: #{e.error}"
	 puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")

	ensure

	date = "('" + Time.now.to_s + "'"
	port = "'" + "#{port}" +"'"
	website = "'" + "#{website}" +"'"
	status = "'" + "#{status}" + "')"

	dbh.query("CREATE TABLE IF NOT EXISTS sites(
		id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
		date VARCHAR(100), 
		port VARCHAR(100),
		website VARCHAR(100),
		status VARCHAR(100)
		)")

	
	dbh.query("INSERT INTO sites (date, port, website, status)
				VALUES
				#{date}, #{port}, #{website}, #{status}
				")
end

dbh.close if dbh

end
